package pers.cj.pdos.mapper;

import org.apache.ibatis.annotations.Param;
import pers.cj.pdos.entity.Goods;
import pers.cj.pdos.entity.GoodsStock;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import pers.cj.pdos.vo.CountVo;
import pers.cj.pdos.vo.GoodsStockVo;
import pers.cj.pdos.vo.GoodsVo;
import pers.cj.pdos.vo.HouseQueryDetailVo;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author chenj
 * @since 2019-11-04
 */
public interface GoodsStockMapper extends BaseMapper<GoodsStock> {
    void insertBatch(@Param("list") List<GoodsStock> list);
    void insertBatchForCheckHouse(@Param("list") List<GoodsStock> list);

    List<CountVo> checkByGoodsList(@Param("list") List<Goods> list);

    /**
     * 根据仓库id和list中的goodsId来获取商品库存表
     * @param houseId
     * @param list
     * @return
     */
    List<GoodsStock> listByHouseAndGoodsList(@Param("houseId")String houseId, @Param("list")List list);


    /**
     * 根据仓库id和map(map的key是id)来获取商品库存表
     * @param houseId
     * @param map
     * @return
     */
    List<Map> listByHouseAndGoodsMap(@Param("houseId")String houseId, @Param("map")Map map);


    List<GoodsVo> listVo(@Param("companyId")String companyId, @Param("page")Integer page, @Param("limit")Integer limit,
                         @Param("goodsTypeId") String goodsTypeId, @Param("goodsStatus") Integer goodsStatus,
                         @Param("filterZero")Boolean filterZero, @Param("search")String search, @Param("storeId")String storeId, @Param("houseId")String houseId);
    Long count(@Param("companyId")String companyId, @Param("goodsTypeId") String goodsTypeId,@Param("goodsStatus") Integer goodsStatus,
                @Param("filterZero")Boolean filterZero, @Param("search")String search, @Param("storeId")String storeId, @Param("houseId")String houseId);

    /**
     * 获取库存总额
     * @return
     */
    BigDecimal getTotalStockAmount(@Param("companyId") String companyId, @Param("storeId")String storeId, @Param("houseId")String houseId);

    /**
     * 获取库存总额最高的商品机器库存总额
     * @return
     */
    Map getHighestStockAmountWithGoods(@Param("companyId") String companyId, @Param("storeId")String storeId, @Param("houseId")String houseId);

    /**
     * 按商品统计库存额
     * @param companyId
     * @param storeId
     * @param houseId
     * @return
     */
    List<Map> getAmountOrderByGoods(@Param("companyId") String companyId, @Param("storeId")String storeId, @Param("houseId")String houseId);

    /**
     * 按门店统计库存额
     * @param companyId
     * @param storeId
     * @param houseId
     * @return
     */
    List<Map> getAmountOrderByStore(@Param("companyId") String companyId, @Param("storeId")String storeId, @Param("houseId")String houseId);

    /**
     * 按仓库统计库存额
     * @param companyId
     * @param storeId
     * @param houseId
     * @return
     */
    List<Map> getAmountOrderByHouse(@Param("companyId") String companyId, @Param("storeId")String storeId, @Param("houseId")String houseId);


    /**
     * 按仓库统计库存数
     * @param companyId
     * @param storeId
     * @param houseId
     * @return
     */
    List<Map> getNumberOrderByHouse(@Param("companyId") String companyId, @Param("storeId")String storeId, @Param("houseId")String houseId);

    List<GoodsVo> listVoByGoodsIds(@Param("goodsIds")List<String> goodsIds, @Param("storeId")String storeId, @Param("houseId")String houseId);

    /**
     * 获取库存查询的详情
     * @param page
     * @param limit
     * @param goodsId
     * @return
     */
    List<HouseQueryDetailVo> listDetailListByGoods(@Param("page")Integer page,
                                                   @Param("limit")Integer limit,
                                                   @Param("goodsId") String goodsId,
                                                   @Param("search")String search,
                                                   @Param("storeId")String storeId,
                                                   @Param("houseId")String houseId);
    /**
     * 获取库存查询的详情的个数
     * @param goodsId
     * @return
     */
    Long countDetailListByGoods(@Param("goodsId") String goodsId,
                                @Param("search")String search,
                                @Param("storeId")String storeId,
                                @Param("houseId")String houseId);

    /**
     * 根据仓库分组取得该商品的库存数量
     * @param goodsId
     * @param storeId
     * @param houseId
     * @return
     */
    List<Map> getGoodsStockGroupByHouse(@Param("companyId") String companyId,@Param("goodsId") String goodsId, @Param("storeId")String storeId, @Param("houseId")String houseId);

    void batchDeleteByGoodsList(@Param("list")List<Goods> list);
}
